package com.qf.controller;/*
 *保护你的大熊
 *2021/11/17
 *21:25
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 验证码校验
 */
@Controller
@RequestMapping("/captcha")
public class CaptchaController {

    /**
     * 跳转到验证码页面
     * @return
     */
    @RequestMapping("/code")
    public String toCode(){
        return "jsp/code";
    }

    /**
     * 校验验证码
     * @return
     */
    @RequestMapping("/test1")
    @ResponseBody
    public String test1(String captcha, HttpSession httpSession){
        //获取服务器中保存的验证码
        String serverCode = String.valueOf(httpSession.getAttribute("captcha"));

        if (serverCode == null) {
            return "time out！";
        }
        if(serverCode.equalsIgnoreCase(captcha)){
            return "success";
        }
        return "error！";
    }
}
